package com.xuecheng.content.api;

import com.xuecheng.base.exception.BusinessException;
import com.xuecheng.content.model.dto.CourseCategoryTreeDto;
import com.xuecheng.content.service.CourseCategoryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 课程分类接口
 * @author Mdd
 * @Github <a href="https://github.com/mdd123cc"/>
 * @Gitee <a href="https://gitee.com/mdd115192"/>
 */


@RestController
public class CourseCategoryController {

    @Resource
    private CourseCategoryService courseCategoryService;


    /**
     * 获得课程分类树状结构
     * @return
     */
    @GetMapping("/course-category/tree-nodes")
    public List<CourseCategoryTreeDto> courseCategoryTree(@RequestParam(required = false,defaultValue = "1") String id){

        List<CourseCategoryTreeDto> courseCategoryTreeDtos = courseCategoryService.queryCourseCategory(id);
        if (courseCategoryTreeDtos == null) {
            throw new BusinessException("接口有误!");
        }
        return courseCategoryTreeDtos;
    }
}
